from sqlalchemy.orm import Session
from app.database import Base, engine, SessionLocal
from app.models import Config, ScanPath, ScanResult

def init_db():
    print("开始初始化数据库...")
    # 创建所有表
    Base.metadata.drop_all(bind=engine)  # 先删除所有表
    Base.metadata.create_all(bind=engine)
    print("数据库表创建完成")

    # 初始化一些测试数据
    # db = SessionLocal()
    # try:
    #     # 添加一些默认配置
    #     test_config = Config(
    #         client_type="qb",
    #         host="localhost",
    #         port=8080,
    #         username="admin",
    #         password="adminadmin",
    #         enabled=True
    #     )
    #     db.add(test_config)
    #
    #     # 添加一些默认扫描路径
    #     test_path = ScanPath(
    #         path="/downloads",
    #         enabled=True
    #     )
    #     db.add(test_path)
    #
    #     db.commit()
    #     print("测试数据初始化完成")
    # except Exception as e:
    #     print(f"初始化测试数据时出错: {e}")
    #     db.rollback()
    # finally:
    #     db.close()

if __name__ == "__main__":
    init_db()
    print("数据库初始化完成")
